var Global = {
    // designSize = cc.size(1280,720),
};

var sizeDesign = cc.size(1280, 720)
// 适配模式是fix height 所以是按高来计算缩放比例
var scalefactor = sizeDesign.height / cc.director.getWinSize().height
Global.scalex = cc.director.getVisibleSize().width * scalefactor / sizeDesign.width;
Global.vsize = cc.director.getVisibleSize();
// cc.log(Global.scalex * sizeDesign.width);
// cc.log(Global.scalex);
// cc.log(cc.director.getWinSizeInPixels());

Global.cardsData = [
    0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d,	//方片
    0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d,	//梅花
    0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d,	//红桃
    0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d,	//黑桃
    0x4e, 0x4f, //小王 大王
];

Global.transDex = function(data) {
    var color = (data >> 4) & 0xf;
    var point = data & 0xf;
    return {color: color, point: point};
};
//排列组合，返回目标数组中制定组合的数组
Global.permutation = function(combNum, objComb, newComb, tmp, max) {
    if (!objComb || !combNum) return;
    if (combNum > objComb.length) return;
    if (!newComb) newComb = [];
    var flag = false;
    if (tmp) {
        var i = 0;
        var count = 0;
        while (i <= tmp.length - 1)
        {
            if (tmp[i] == 1 && tmp[i + 1] == 0) {
                tmp[i] = 0;
                tmp[i + 1] = 1;
                flag = true;
                break;
            }
            if (tmp[i] == 1) count++;
            i++;
        }
        for (var j = 0; j < i; j++)
        {
            tmp[j] = 0
        }
        for (var j = 0; j < count; j++)
        {
            tmp[j] = 1
        }
    } else {
        tmp = [];
        for (var i = 0, len = objComb.length; i < len; i++)
        {
            tmp[i] = 0;
        }
        for (var i = 0; i < combNum; i++)
        {
            tmp[i] = 1;
        }
        flag = true;
    }
    if (flag) {
        var t = {};
        t.data = [];
        for (var i = 0, len = tmp.length; i < len; i++)
        {
            if (tmp[i] == 1) t.data.push(objComb[i]);
        }
        if (t.data.length > 0) newComb.push(t);
        if (!max || newComb.length < max)
            Global.permutation(combNum, objComb, newComb, tmp, max);
    }
    return newComb;
};

Global.random = function(min, max) {
    return Math.floor(Math.random() * (max - min + 1) + min);
};
